package com.xuecheng.test.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author Andrew Yang
 * @ClassName RabbitmqConfig
 * @Description
 * @Package com.xuecheng.test.rabbitmq.config
 * @create 2020-02-05 22:57
 */
@Configuration
public class RabbitmqConfig {
    public static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
    public static final String QUEUE_INFORM_SMS = "queue_inform_sms";
    public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";

    /**
     * @Method: EXCHANGE_TOPICS_INFORM
     * @Author: Andrew Yang
     * @Date: 2020/2/5 23:02
     * @param 
     * @Return org.springframework.amqp.core.Exchange
     * @Description: 交换机设置 ExchangeBuilder提供了fanout、direct、topic、header交换机类型的配置
     */
    @Bean(EXCHANGE_TOPICS_INFORM)
    public Exchange EXCHANGE_TOPICS_INFORM() {
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
    }

    /**
     * @Method: QUEUE_INFORM_SMS
     * @Author: Andrew Yang
     * @Date: 2020/2/5 23:05
     * @param 
     * @Return org.springframework.amqp.core.Queue
     * @Description: 声明sms队列
     */
    @Bean(QUEUE_INFORM_SMS)
    public Queue QUEUE_INFORM_SMS() {
        return new Queue(QUEUE_INFORM_SMS);
    }

    /**
     * @Method: QUEUE_INFORM_EMAIL
     * @Author: Andrew Yang
     * @Date: 2020/2/5 23:08
     * @param
     * @Return org.springframework.amqp.core.Queue
     * @Description: 声明email队列
     */
    @Bean(QUEUE_INFORM_EMAIL)
    public Queue QUEUE_INFORM_EMAIL() {
        return new Queue(QUEUE_INFORM_EMAIL);
    }

    @Bean
    public Binding BINDING_QUEUE_INFORM_SMS(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
                                            @Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.sms.#").noargs();
    }

    @Bean
    public Binding BINDING_QUEUE_INFORM_EMAIL(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue,
                                            @Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("inform.#.email.#").noargs();
    }
}
